package com.example.myworkers.controller;

import com.example.myworkers.model.Grant;
import com.example.myworkers.model.Record;
import com.example.myworkers.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编写者：门硕然
 */

@Api(tags = "Record")
@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private RecordService recordService;

    @ApiOperation(value = "添加方法")
    @PostMapping("/addRecord")
    @CrossOrigin
    public int addRecord(@RequestBody Record record){
        System.out.println("进入添加信息接口");
        return recordService.insertRecord(record);
    }

    @ApiOperation(value = "查询方法-单个")
    @GetMapping("/getOne")
    @CrossOrigin
    public Record getRecord(int id){
        System.out.println("进入单条查询接口");
       Record record=recordService.selectRecord(id);
        System.out.println("返回的数据集合为"+record.getName());
        return record;
    }



    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteRecord")
    @CrossOrigin
    public int deleteRecord(int id){
        System.out.println("进入删除接口");
        int returnValue=0;
        if (id!=0){
            returnValue=recordService.deleteRecord(id);
        }
        return returnValue;
    }

    @ApiOperation(value = "修改方法")
    @PostMapping("/editRecord")
    @CrossOrigin
    public int editRecord(@RequestBody Record record){
        System.out.println("进入修改接口");
        return recordService.updateRecord(record);
    }



}
